import type { ComponentStyleIdType } from '../../../types/interfaces'
import { BaseModule } from '../../../lib/abstract'
import { ComponentStyleId, logger } from '../../../types/constants'
import { ConfigManager } from '../../config_manager'

interface Config {
  enabled?: boolean
}

export class ThemeSync extends BaseModule {
  readonly id: string = 'theme_sync'
  readonly styleId: string = ComponentStyleId[this.name]
  isInitialized: boolean = false
  readonly supportedPlatforms: string[] = ConfigManager.getInstance().moduleSupportedPlatforms(this.name)
  private static instance: ThemeSync

  config: Config = {
    enabled: true,
  }

  get name(): ComponentStyleIdType {
    return 'ThemeSync'
  }

  /**
   * 获取单例实例
   */
  public static getInstance(): ThemeSync {
    if (!ThemeSync.instance) {
      ThemeSync.instance = new ThemeSync()
    }
    return ThemeSync.instance
  }

  core(): void {
    this.loadConfig()

    if (!this.config.enabled)
      return

    this.applyTheme()
  }

  onToggleCallback(_id: string, checked: boolean): void {
    super.onToggleCallback(_id, checked)
  }

  /**
   * 应用主题
   */
  applyTheme(): void {
  }

  applyConfig(config: Partial<Config>): void {
    super.updateConfig(config)

    this.applyTheme()

    logger.info(`[${this.name}] Config updated and apply`, this.config)
  }

  getStyles(): string {
    return `
`
  }
}
